<!DOCTYPE html>
<html lang="zh" xmlns="http://www.w3.org/1999/html">

<head>
    <meta charset="UTF-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>库存管理-备件信息</title>

    <link href="../plugin/bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../plugin/bootstrap-table-1.11.1/bootstrap-table.min.css" rel="stylesheet"/>
    <link href="../plugin/sweetalert-6.6.2/sweetalert2.min.css" rel="stylesheet"/>
    <link href="../plugin/jstree/jstree.min.css" rel="stylesheet">
    <link href="../plugin/bootstrap-fileinput-master/fileinput.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="../plugin/fileupload/css/jquery.fileupload.css">
    <link href="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet"/>


    <script src="../plugin/jquery-3.2.1/jquery-3.2.1.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/bootstrap-table.js"></script>
    <script src="../plugin/bootstrap-table-1.11.1/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.min.js"></script>
    <script src="../plugin/bootstrap-3.3.7/plugin/datatimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="../plugin/sweetalert-6.6.2/sweetalert2.min.js"></script>
    <script src="../plugin/jquery-3.2.1/jquery.formautofill.min.js"></script>
    <script src="../plugin/soul/utils3.js"></script>
    <script src='../js/base.js'></script>
    <!--<script src="../plugin/soulUtils/soul_utils.js"></script>-->
    <script src='../plugin/jquery-3.2.1/jquery.form.js'></script>
    <script src="../plugin/jquery-3.2.1/jquery.serializejson.js"></script>
    <script src="../plugin/jstree/jstree.min.js"></script>
    <script src="../plugin/jquery-zoomify/zoomify.min.js"></script>
    <script src="../plugin/bootstrap-fileinput-master/fileinput.min.js"></script>
</head>

<style type="text/css">

</style>

<body>

<!-- 设备信息导入模态框 -->
<div class="modal fade in" data-backdrop="static" id="accessory_modal_edit_info">
    <form id="ajaxForm" enctype="multipart/form-data" onsubmit="return false">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal">
                        <span>&times;</span>
                    </button>
                    <h4 class="modal-title">
                        <b>配件信息</b>
                    </h4>
                </div>
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="form-group"><label class="col-sm-2 control-label">医院名称</label>
                            <div class="col-sm-9">
                                <select class="form-control" id="hospitalId" name="hospitalId"
                                        class="form-control"></select>
                                &nbsp;&nbsp;
                            </div>
                        </div>
                        <div class="form-group"><label class="col-sm-2 control-label">导入文件:</label>
                            <div class="col-sm-9">
                                <input type="file" id="file" name="file" class="form-control" placeholder="请输入文本"></div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-primary" onclick="doUpload()">确认</button>
                        <button class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<!-- 配件调拨模态框 -->
<div class="modal fade in" data-backdrop="static" id="accessory_modal_transfers_info">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal">
                    <span>&times;</span>
                </button>
                <h4 class="modal-title">
                    <b>配件调拨信息</b>
                </h4>
            </div>
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="form-group"><label class="col-sm-2 control-label">医院名称:</label>
                        <div class="col-sm-9">
                            <select class="form-control" id="transfers_hospitalId" name="transfers_hospitalId"
                                    class="form-control"></select>
                            &nbsp;&nbsp;
                        </div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">调拨数量:</label>
                        <div class="col-sm-9">
                            <input type="text" id="transfers_amount" name="transfers_amount" class="form-control" placeholder="请输入文本">
                            &nbsp;&nbsp;
                        </div>
                    </div>
                    <div></div>
                    <!--<div class="form-group"><label class="col-sm-2 control-label">设备序列号:</label>-->
                        <!--<div class="col-sm-9">-->
                            <!--<input type="text" id="transfers_equipment_serial" name="transfers_equipment_serial" class="form-control" placeholder="请输入文本">-->
                            <!--&nbsp;&nbsp;-->
                        <!--</div>-->
                    <!--</div>-->
                    <div class="form-group"><label class="col-sm-2 control-label">使用者:</label>
                        <div class="col-sm-9">
                            <input type="text" id="transfers_staff_name" name="transfers_staff_name" class="form-control" placeholder="请输入文本">
                            &nbsp;&nbsp;
                        </div>
                    </div>
                    <div class="form-group"><label class="col-sm-2 control-label">联系方式:</label>
                        <div class="col-sm-9">
                            <input type="text" id="transfers_staff_contact" name="transfers_staff_contact" class="form-control" placeholder="请输入文本">
                            &nbsp;&nbsp;
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-primary" onclick="comfirm()">确认</button>
                    <button class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        var currentAccessoryId;
        var currentAccessoryAmount;
        var resp = AjaxUtil.isLogin();
        if (!resp) return;
        var module = 'accessory';
        var query = [{
            id: 'hospital',
            type: 'select',
            name: '医院名称',
            paramName: 'hospitalId',
            items: 'hospital/selectItem'
        }, {
            id: 'name',
            type: 'text',
            name: '配件名称',
            paramName: 'name',
            palceholder: ''
        }, {
            id: 'accessoryBrandName',
            type: 'text',
            name: '品牌',
            paramName: 'accessoryBrandName',
            palceholder: ''
        }, {
            id: 'accessoryModel',
            type: 'text',
            name: '规格型号',
            paramName: 'accessoryModel',
            palceholder: ''
        }, {
            id: 'accessorySize',
            type: 'text',
            name: '配件尺寸',
            paramName: 'accessorySize',
            palceholder: ''
        }];
        var toolbar = {
            default: [true, true, true, true],// back;add;edit;remove
            dialog: [60, 2, 9],//对话框参数:模态框宽度(百分比);表单标题宽度;表单输入框宽度
            extra: [{
                name: '导入',
                type: 'file',
                glyphicon: 'import',
                onclick: 'import',
            }, {
                name: '导出',
                glyphicon: 'export',
                onclick: 'export',
            }, {
                name: '调拨',
                glyphicon: 'retweet',
                onclick: 'transfers',
            }]
        };
        // 表单内容配置
        var formElement = [{
            action: [false, true],
            type: 'hidden', // 表单类型
            name: 'accessoryId', // 字段名称
        }, {
            action: [true, true],
            id: 'hospitalId',
            type: 'select',
            label: '所属医院',
            name: 'hospitalId',
            items: "hospital/selectItem"
        }, {
            action: [true, true],
            type: 'text',
            label: '配件名称',
            name: 'name',
        }, {
            action: [true, true],
            type: 'text',
            label: '品牌',
            name: 'accessoryBrandName',
        }, {
            action: [true, true],
            type: 'text',
            label: '规格型号',
            name: 'accessoryModel',
        }, {
            action: [true, true],
            type: 'text',
            label: '数量',
            name: 'amount',
        }, {
            action: [true, true],
            type: 'text',
            label: '单位',
            name: 'unit',
        },{
            action: [true, true],
            type: 'text',
            label: '配件尺寸',
            name: 'accessorySize',
        }, {
            action: [true, true],
            type: 'text',
            label: '备注',
            name: 'remark',
        }, {
            action: [true, true],
            type: 'images',
            label: '配件图片',
            name: 'photo',
            module: 'accessory',
            maxCount: 10
        }];

        var bootstrapTable = {
            url: '',
            columns: [{
                radio: true
            },{
                field: 'hospitalName',
                title: '所属医院',
            }, {
                field: 'name',
                title: '配件名称',
            }, {
                field: 'accessoryBrandName',
                title: '品牌',
            }, {
                field: 'accessoryModel',
                title: '规格型号',
            }, {
                field: 'accessorySize',
                title: '尺寸',
            }, {
                field: 'amount',
                title: '数量',
            },{
                field: 'unit',
                title: '单位',
            }, {
                field: 'remark',
                title: '备注',
            }, {
                field: 'photo',
                title: '配件图片',
                formatter: function (value) {
                    return BootstrapTableUtil.formatter.image(value, 'accessory', '60');
                }
            },]
        };

        accessory = SingleTablePageCreateUtil.createInstance(module, query, toolbar, formElement, bootstrapTable);

        accessory.onAddModalShowBefore = function () {
            $('#accessory_modal_add input[name="name"]').val("");
            $('#accessory_modal_add input[name="accessoryBrandName"]').val("");
            $('#accessory_modal_add input[name="accessoryModel"]').val("");
            $('#accessory_modal_add input[name="amount"]').val("");
            $('#accessory_modal_add input[name="accessorySize"]').val("");
            $('#accessory_modal_add input[name="remark"]').val("");
            return true;
        };

        accessory.onEditModalShowBefore = function (row) {
            FileinputUtil.initPreview("#accessory_form_edit_undefined", "accessory", row.photo);
            return row;
        };

        //点击导入显示模态框
        accessory.import = function () {
            $('#hospitalId').empty();
            $('#file').val('');
            var resp = AjaxUtil.getJson('hospital/selectItem').obj;
            var s = '<option value>' + '请点击下拉框选择' + '</option>';
            for (var i = 0; i < resp.length; i++) {
                s += '<option value="' + resp[i].value + '">' + resp[i].name + '</option>';
            }
            $('#hospitalId').append(s);
            $('#accessory_modal_edit_info').modal('show');
        };

        //点击确认按钮提交表单内容
        doUpload = function () {
            var formData = new FormData($("#ajaxForm")[0]);
            $.ajax({
                url: '/accessory/excelImport?token=' + BaseConfig.token,
                type: 'POST',
                data: formData,
                async: true,
                cache: false,
                contentType: false,
                processData: false,
                success: function (res) {
                    if (res.code == 412) {
                        SwalUtil.error(res.msg);
                    }
                    if (res.code == 200) {
                        $('#accessory_modal_edit_info').modal('hide');
                        SwalUtil.success(res.msg);
                        $('#accessory_table').bootstrapTable('refresh');
                    }
                },
            });
            return false;
        }

        //点击导出
        accessory.export = function () {
            var par = $('#accessory_form').serializeJSON();
            var url = '';
            for (var key in par) {
                url += '&' + key + '=' + par[key];
            }
            url = BaseConfig.preUrl + 'accessory/downloadExcel?token=' + BaseConfig.token + url;
            window.open(url);
        };
        //点击调拨显示模态框
        accessory.transfers = function () {
            var row = TablePageCreatePublicUtil.getRowFromTable('#accessory_table');
            if (!row) return false;
            $('#transfers_hospitalId').empty();
            var resp = AjaxUtil.getJson('hospital/selectItem').obj;

            var s = '<option value>' + '请点击下拉框选择' + '</option>';
            for (var i = 0; i < resp.length; i++) {
                s += '<option value="' + resp[i].value + '">' + resp[i].name + '</option>';
            }
            $('#transfers_hospitalId').append(s);
            currentAccessoryId = row.accessoryId;
            currentAccessoryAmount = row.amount;
            $('#transfers_amount').val('');
            $('#transfers_staff_name').val('');
            $('#transfers_staff_contact').val('');
            $('#accessory_modal_transfers_info').modal('show');
        };

         //调拨确认
        comfirm = function () {
            var transfersAmount = $('#transfers_amount').val();
            var transfersHospital=$('#transfers_hospitalId').val();
            // var transfersEquipmentSerial=$('#transfers_equipment_serial').val();
            var transfersStaffName=$('#transfers_staff_name').val();
            var transfersStaffContact=$('#transfers_staff_contact').val();
            //若用户没有修改设备数量,则不发送请求到后端
            if (transfersAmount <=0){
               SwalUtil.error("调拨数量不能小于1")
                return;
            }
            if (transfersAmount>currentAccessoryAmount){
                SwalUtil.error("调拨数量大于配件数量")
                return;
            }
            var resp = AjaxUtil.postJson('accessory/transfers', {
                currentAccessoryId: currentAccessoryId,
                transfersAmount: transfersAmount,
                transfersHospital:transfersHospital,
                // transfersEquipmentSerial:transfersEquipmentSerial,
                transfersStaffName:transfersStaffName,
                transfersStaffContact:transfersStaffContact
            });
            if (resp) {
                SwalUtil.success(resp.msg);
                $('#accessory_modal_transfers_info').modal('hide');
                $('#accessory_table').bootstrapTable('refresh');
            }
        }

    });


</script>


</body>

</html>